{% extends "admin/base_site.html" %}
{% load i18n admin_urls static admin_list %}

{% block extrastyle %}
  {{ block.super }}

  <link href="{% static "fontawsome/css/font-awesome.min.css" %}" rel="stylesheet">
  <link href="{% static "css/bootstrap-grid.css" %}" rel="stylesheet">
  <link href="{% static "datatables/1.10/css/datatables.min.css" %}" rel="stylesheet">
  <link href="{% static "datatables/1.10/DataTables-1.10.18/css/jquery.dataTables.min.css" %}" rel="stylesheet">
{% endblock %}



{% block breadcrumbs %}
  <div class="breadcrumbs">
    <a href="{% url 'admin:index' %}">{% trans 'Home' %}</a> &rsaquo;
    <a href="{% url 'admin:app_list' app_label='qa' %}">{% trans "QC" %}</a> &rsaquo;
    {% trans "Import Test Pack" %}
  </div>
{% endblock %}

{% block coltype %}flex{% endblock %}


{% block content %}

<div class="container-fluid">
  <div class="row">
    <div class="col-sm-12">
      <p>
        {% blocktrans %}
        On this page you may import Test Lists, Test List Cycles, or individual
        Tests from a Test Pack.
        {% endblocktrans %}
      </p>
    </div>
  </div>

  <div class="row">

    <div class="col-sm-8">
      <div class="row">
        <div class="col-sm-12 tp-container">
          <hr/>
          <h2>{% trans "Test Lists To Include" %}</h2>

          <em class="loading">{% trans "Loading Test List table" %}...</em>
          <table id="testlists-table" style="display: none">
            <thead>
              <tr>
                <th>{% trans "ID" %}</th>
                <th>{% trans "Test List" %}</th>
                <th>{% trans "Description" %}</th>
              </tr>
            </thead>
            <tbody>
              {% for list in testlists %}
                <tr>
                  <td>{{ list.id }}</td>
                  <td>{{ list.name }}</td>
                  <td>{{ list.description }}</td>
                </tr>
              {% endfor %}
            </tbody>

          </table>
        </div>
      </div>

      <div class="row">
        <div class="col-sm-12 tp-container">
          <hr/>
          <h2>{% trans "Test List Cycles To Include" %}</h2>

          <em class="loading">{% trans "Loading Test List Cycle table" %}...</em>
          <table id="testlistcycles-table" style="display: none">
            <thead>
              <tr>
                <th>{% trans "ID" %}</th>
                <th>{% trans "Cycle" %}</th>
                <th>{% trans "Description" %}</th>
              </tr>
            </thead>
            <tbody>
              {% for cycle in cycles %}
                <tr>
                  <td>{{ cycle.id }}</td>
                  <td>{{ cycle.name }}</td>
                  <td>{{ cycle.description }}</td>
                </tr>
              {% endfor %}
            </tbody>

          </table>
        </div>
      </div>

      <div class="row">
        <div class="col-sm-12 tp-container">
          <hr/>
          <h2>{% trans "Select Extra Tests To Include" %}</h2>

          <p>
            <em>
              {% blocktrans %}
              Note that there is no need to select tests that are already
              included as part of a test list
              {% endblocktrans %}
            </em>
          </p>

          <em class="loading">{% trans "Loading Test table" %}...</em>
          <table id="tests-table" style="display: none">
            <thead>
              <tr>
                <th>{% trans "ID" %}</th>
                <th>{% trans "Test" %}</th>
                <th>{% trans "Category" %}</th>
                <th>{% trans "Type" %}</th>
                <th>{% trans "Description" %}</th>
              </tr>
            </thead>
            <tbody>
              {% for test in tests %}
                <tr>
                  <td>{{ test.id }}</td>
                  <td>{{ test }}</td>
                  <td>{{ test.category.name }}</td>
                  <td>{{ test.get_type_display }}</td>
                  <td>{{ test.description }}</td>
                </tr>
              {% endfor %}
            </tbody>

          </table>
        </div>
      </div>
    </div>

    <div class="col-sm-4">
      <form method="post" action>
        {% csrf_token %}
        <h2>{% trans "Load Test Pack" %}</h2>
        <div class="row">
          <div class="col-sm-6">
            {% trans "Test Pack File" %}:
          </div>
          <div class="col-sm-6" style="text-align: right">
            <input type="file" name="testpack" id="id_testpack" required="">
            {{ form.testpack_data }}
            {{ form.testpack_data.errors }}
          </div>
        </div>
        <div class="row">
          <div class="col-sm-6">
            {% trans "Test Pack Name" %}:
          </div>
          <div id="name" class="col-sm-6" style="text-align: right"></div>
        </div>
        <div class="row">
          <div class="col-sm-6">
            {% trans "Test Pack Created By" %}:
          </div>
          <div id="created-by" class="col-sm-6" style="text-align: right"></div>
        </div>
        <div class="row">
          <div class="col-sm-6">
            {% trans "Test Pack Generator Version" %}:
          </div>
          <div id="version" class="col-sm-6" style="text-align: right"></div>
        </div>
        <div class="row">
          <div class="col-sm-6">
            {% trans "Test Pack Description" %}:
          </div>
          <div id="description" class="col-sm-6" style="text-align: right"></div>
        </div>
        <div>
          {{ form.testlists }}
          {{ form.testlistcycles }}
          {{ form.tests }}
        </div>
        <h2>{% trans "Import Summary" %}</h2>
        <hr/>
        <div id="summary">

          <div class="row">
            <div class="col-sm-6">{% trans "Test Lists" %}:</div>
            <div class="col-sm-6" style="text-align: right" id="testlists-summary">{% trans "0 Selected" %}</div>
          </div>

          <div class="row">
            <div class="col-sm-6">{% trans "Test Lists Cycles" %}:</div>
            <div class="col-sm-6" style="text-align: right" id="testlistcycles-summary">{% trans "0 Selected" %}</div>
          </div>

          <div class="row">
            <div class="col-sm-6">{% trans "Tests" %}:</div>
            <div class="col-sm-6" style="text-align: right" id="tests-summary">{% trans "0 Selected" %}</div>
          </div>

        </div>
        <hr/>
        <div class="submit-row">
          <input type="submit" value="{% trans "Import" %}" class="default">
        </div>
      </form>
    </div>

  </div>
</div>

{% endblock %}

{% block footer %}
<script src="{% static "lodash/js/lodash.js" %}"></script>
<script type="text/javascript">
    window.parseVersion = function(v){
      return _.map(v.split("."), function(a){return parseInt(a, 10);});
    };

    window.VERSION = "{{ VERSION }}";
    window.version = window.parseVersion(window.VERSION);

    window.test_types = {{ test_types | safe }};
</script>

<script src="{% static "jquery/js/jquery.min.js" %}"></script>

<script src="{% static "datatables/1.10/js/datatables.min.js" %}"></script>
<script src="{% static "js/testpack-import.js" %}"></script>

{% endblock %}
